<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('流程模型列表')" />
	<th:block th:include="include :: list-css" />
</head>
<body>
	<div class="main-content">
		<div class="content-right">
			<div class="search-top">
				<span>查询条件</span>
				<a href="javascript:;" layadmin-event="flexible" class="menuBtn">
					<i class="layui-icon layui-icon-spread-left" id="LAY_app_flexible" style="color: #fff;"></i>
				</a>
			</div>
			<div class="panel layout-expand layui-expand-east">
			    <div class="panel-header">
			        <div class="panel-tool" style="text-align: center; width: 26px;height: 30px;line-height: 30px;">
			            <a href="javascript:;" layadmin-event="flexible" class="menuBtn">
			                <i class="layui-icon layui-icon-shrink-right" id="LAY_app_flexible" style="color: #fff;"></i>
			            </a>
			        </div>
			    </div>
			    <div class="panel-body panel-title" style="text-align: center; width: 26px;">查<br>询<br>条<br>件</div>
			</div>
	       	<form class="layui-form">
				<th:block th:include="listinclude :: searchRight('page')" />
			</form>
	   	</div>
	    <div class="mid-content">
	        <table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
	    </div>
	</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: searchJS" />
<th:block th:include="listinclude :: list-templeat" />
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <div class="layui-btn layui-btn-normal layui-table-tools" lay-event="addbtn" onclick="$.operate.add()" shiro:hasPermission="flowable:model:add">
            <p class="dhicon dh-zu4664" style="color:white;font-size:14px"><span class="fa_span">新增模型</span></p>
        </div>
		<div class="layui-btn layui-table-tools importbtn-bg" lay-event="importModel" id="uploadModel" shiro:hasPermission="flowable:model:add">
			<i class="dhicon dh-zu4688"></i> 导入流程文件
		</div>
    </div>
</script>
<script type="text/html" id="barDh">
    <a class="layui-btn layui-btn-xs dhicon dh-edit" lay-event="edit"  shiro:hasPermission="flowable:model:edit"> 在线设计</a>
    <a class="layui-btn layui-btn-xs dhicon dh-play-circle-o layui-btn-normal" lay-event="deploy"  shiro:hasPermission="flowable:model:edit"> 部署</a>
    <a class="layui-btn layui-btn-xs dhicon dh-search layui-btn-warm"  lay-event="export"  shiro:hasPermission="flowable:model:export"> 导出</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs dhicon dh-remove" lay-event="delete" shiro:hasPermission="flowable:model:delete"> 删除</a>
</script>
<script type="text/html" id="templet_version">
	v.{{d.version}}
</script>
<script th:inline="javascript">
     /*<![CDATA[*/
     var prefix = ctx + "flowable/model";
     var gridColumns=[[${gridColumns}]];
     var moduleTable=[[${moduleTable}]];
     /*]]>*/
</script>
<script type="text/javascript">
var $,layer,form,table,laydate,upload;
var wherestr={};
layui.use(['laydate','table','form','layer','jquery','upload'], function () {
	$ = layui.$,layer = layui.layer,form = layui.form,table = layui.table,laydate = layui.laydate,upload = layui.upload;
	serachRender();//查询条件初始渲染集合
    $.tablelist.init({
        elem: '#dhtable'
        ,modalName: "流程模型"
        ,createUrl: prefix + "/add"
        ,updateUrl: prefix + "/edit/{id}"
        ,url: prefix + "/list"
        ,where: {field: 'createTime',order: 'desc'}
        ,sort:true
        ,cols: [gridColumns.gridBody
        ]
        ,toolbar: '#toolbar'
   		,defaultToolbar: [{title:'列设置',layEvent: 'fieldSet',icon: 'layui-icon-set'}]
        ,height:'full-36',
    });
	initAddfile();
    //监听工具条
    table.on('tool(ftable)', function (obj) {
        var data = obj.data;
        if (obj.event === 'edit') {
            var url = "/modeler/index.html#/editor/" + data.id;
            parent.layui.index.openTabsPage(url, '流程模型在线设计');
        }else if(obj.event === 'delete'){ //删除
            $.modal.confirmCom("确定要删除["+data.name +"]吗？",function(){
                $.operate.post(prefix + "/delete",{'ids':data.id},function(result){
                    allReload(result)
                });
            });
        }else if(obj.event === 'export'){ //导出
            var modelId = data.id;
            window.location.href = prefix + "/export/" + modelId;
			top.$('.page-loading').hide();
        }else if(obj.event === 'deploy'){ //部署
            var modelId = data.id;
            $.modal.confirmCom("您确认要部署模型["+data.name +"]吗？",function(){
                $.operate.post(prefix + "/deploy/" + data.id, "",function(result){
                    if (result.code == "0"){
                        $.modal.msgSuccess(result.msg);
                    }else {
                        $.modal.msgError(result.msg);
                    }
                });
            });
        }
    });
    //监听排序事件
    table.on('sort(ftable)', function(obj){
        $.tablelist.sort('dhtable',obj);
    });
	//头工具栏事件
	table.on('toolbar(ftable)', function(obj){
    	switch(obj.event){
      	case 'fieldSet':
    		filedSet(moduleTable);
    		break;
    	};
	});
    var active = {
        reload: function (formData) {
            table.reload('dhtable', {
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where:{
                    key:$("#modelKey-kw").val(),
                    name:$("#modelName-kw").val(),
                    category:$("#modelCategory-kw").val()
                }
            });
        },
    };
})
function initAddfile(){
	upload.render({ //允许上传的文件后缀
		elem: '#uploadModel'
		,url: prefix +'/importSave'
		,accept: 'file' //普通文件
		,field:'processModel'
		,done: function(res){
			if (res.code == "0"){
				$.modal.msgSuccess(res.msg);
				allReload(res);
			}else {
				$.modal.msgError(res.msg);
			}
		},error: function(){
			$.modal.msgError("导入流程模型文件失败！");
		}
	})
}
//搜索按钮：重复监听（search.js），添加页面专属动作
$('#btn-search').on('click', function () {
	setTimeout(function(){
		initAddfile();
	}, 1000);
});
//重新加载
function allReload(result){
    if(result.code==0){
        setTimeout(function(){
            layer.closeAll();
            table.reload('dhtable', {url: prefix + "/list",page:{curr: 1}});
			initAddfile();
        }, 1000);
    }
}
</script>
</body>
</html>
